package cn.lingyangwl.agile.pay.pay.controller.refund;

import cn.lingyangwl.agile.pay.common.annotation.PayCheck;
import cn.lingyangwl.agile.pay.common.service.RefundOrderService;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.agile.pay.model.rqrs.RefundOrderQL;
import cn.lingyangwl.agile.pay.model.rqrs.pay.refund.RefundOrderRQ;
import cn.lingyangwl.agile.pay.model.rqrs.pay.refund.RefundOrderRS;
import cn.lingyangwl.agile.pay.pay.process.refund.RefundOrderProcess;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 商户发起退款 controller
 *
 * @author shenguangyang
 */
@Slf4j
@RestController
@RequestMapping("/payMgt/refund")
public class RefundOrderMgtController {
    @Resource
    private RefundOrderService refundOrderService;
    @Resource
    private RefundOrderProcess refundOrderProcess;

    /**
     * 分页 退款
     */
    @GetMapping("/pageRefund")
    @RamResource(action = "pay:refund:list", name = "查询退款订单列表", type = ActionType.READ)
    public Resp<IPage<RefundOrderRS>> page(@Validated RefundOrderQL req) {
        return Resp.ok(refundOrderService.pageRefundOrder(req));
    }

    /**
     * 申请退款
     */
    @PostMapping("/refundOrder")
    @PayCheck
    @RamResource(action = "pay:refund:refundOrder", name = "申请退款", type = ActionType.WRITE)
    public Resp<?> refundOrder(@RequestBody @Validated RefundOrderRQ rq) {
        return refundOrderProcess.refundOrder(rq);
    }

}
